import React, {Component} from 'react'

import {Router, Route, IndexRoute, IndexRedirect, browserHistory} from 'react-router'
import {syncHistoryWithStore, routerReducer} from 'react-router-redux'

import {Provider} from 'react-redux'
import {createStore, combineReducers, applyMiddleware, compose} from 'redux'
import thunk from 'redux-thunk'
import reducers from './reducers/'

import Login from './moduls/login/'
import Main from './moduls/main/'
import Home from './moduls/home/'
import Dashboard from './moduls/dashboard/'
import User from './moduls/user/'
import Apps from './moduls/apps/'

const store = createStore(
    combineReducers({
        ...reducers,
        // auth: authReducer,
        routing: routerReducer,
    }),
    compose(
        applyMiddleware(thunk),
        window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
    ),
)

// Now you can dispatch navigation actions from anywhere!
// store.dispatch(push('/foo'))
const history = syncHistoryWithStore(browserHistory, store)


class App extends Component {
    constructor(props) {
        super(props);
        this.state = {}
    }

    render() {
        return (
            <Provider store={store}>
                <div>
                    <Router history={history}>
                        <Route path="/" component={Home}>
                            <IndexRedirect to='login'/>
                            <Route path='/login' component={Login} store={store}/>
                            <Route path='/admin' component={Main} store={store}>
                                <IndexRoute component={Dashboard}/>
                                <Route path='/admin/user' component={User}/>
                                <Route path='/admin/dashboard' component={Dashboard}/>
                                <Route path='/admin/apps' component={Apps}/>
                            </Route>
                        </Route>

                    </Router>
                </div>
            </Provider>
        )
    }
}

export default App;
